package com.rub.android.utils

import android.os.Environment
import android.os.StatFs
import java.io.File

class SystemAttributes {

    open fun getMemoryInfo():String{
        //获取环境变量Data目录
        val dataFileDir: File = Environment.getDataDirectory()
        return getDevSpace(dataFileDir.path)
    }
    /*
     * 获取磁盘信息
     * @param sdcardRoot 指定sdcard路径
     */
    private fun getDevSpace(sdcardRoot: String): String {
        var state = Environment.getExternalStorageState()// 获取 sdcard 状态
        if (Environment.MEDIA_MOUNTED == state) {        //判断sdcard 是否可以用
            val sf = StatFs(sdcardRoot)     //sdcard 类 空间信息
            val blockSize = sf.blockSize           //一个block大小
            val blockCount = sf.blockCount          //总block 数
            val availCount = sf.availableBlocks   //  剩余block 数
            var M: Int = 1048576// 字节转MB
            val G = 1073741824
            val totalSize = blockSize * blockCount / G   //  总空间
            val surplus = availCount * blockSize / G        //   剩余空间
            return "设备总空间：" + totalSize + "GB " + " 剩余空间：" + surplus + "GB";
        }
        return ""
    }
}